import request from '@/config/axios'

/** 订单信息 */
export interface Order {
          id: number; // 主键
          tradeSn: string; // 交易编号
          orderSn: string; // 订单编号
          studentId: number; // 学生ID
          courseId: string; // 课程ID（多个用逗号隔开）
          levelId: number; // 会员等级id
          originPrice: number; // 原价
          salePrice: number; // 售价
          discountAmount: number; // 优惠金额
          refundAmount: number; // 退款金额
          status: number; // 订单状态（0待支付/1已支付/2退款中/3已退款/4已关闭）
          orderType: number; // 订单类型（0课程订单/1会员订单）
  }

// 订单 API
export const OrderApi = {
  // 查询订单分页
  getOrderPage: async (params: any) => {
    return await request.get({ url: `/train/order/page`, params })
  },

  // 查询订单列表
  getOrderListByCommodityId: async (id: number) => {
    return await request.get({ url: `/train/order/listByCommodityId?id=` + id })
  },

  // 查询订单详情
  getOrder: async (id: number) => {
    return await request.get({ url: `/train/order/get?id=` + id })
  },

  // 新增订单
  createOrder: async (data: Order) => {
    return await request.post({ url: `/train/order/create`, data })
  },

  // 修改订单
  updateOrder: async (data: Order) => {
    return await request.put({ url: `/train/order/update`, data })
  },

  // 删除订单
  deleteOrder: async (id: number) => {
    return await request.delete({ url: `/train/order/delete?id=` + id })
  },

  /** 批量删除订单 */
  deleteOrderList: async (ids: number[]) => {
    return await request.delete({ url: `/train/order/delete-list?ids=${ids.join(',')}` })
  },

  // 导出订单 Excel
  exportOrder: async (params) => {
    return await request.download({ url: `/train/order/export-excel`, params })
  }
}
